using MicroMsg.Manager;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace MicroMsg.UI.UserContrl
{
	public class SmileyProcess : BaseInlineProcess
	{
		protected override int GetProbablyStartPos(string text, int startIndex)
		{
			if (string.IsNullOrEmpty(text))
			{
				return -1;
			}
			int num = text.IndexOf("[", startIndex);
			int num2 = text.IndexOf("/", startIndex);
			if (num >= 0 && num2 >= 0)
			{
				return Math.Min(num, num2);
			}
			if (num >= 0)
			{
				return num;
			}
			if (num2 >= 0)
			{
				return num2;
			}
			return -1;
		}
		protected override Inline GetCurrentElement(string text, int startIndex, ref int elementLen, ref string elementStr)
		{
			if (startIndex < 0)
			{
				return null;
			}
			for (int i = 1; i <= SmileyManager.GetInstance().GetMaxSmileyTxtLen() - 1; i++)
			{
				if (text.get_Length() > startIndex + i)
				{
					string text2 = text.Substring(startIndex, i + 1);
					string smileySrc = SmileyManager.GetInstance().getSmileySrc(text2);
					if (smileySrc != null)
					{
						elementLen = i + 1;
						elementStr = text2;
						InlineUIContainer inlineUIContainer = new InlineUIContainer();
						Image image = new Image();
						image.set_Width(30.0);
						image.set_Height(30.0);
						image.set_Margin(new Thickness(2.0, 7.0, 2.0, -5.0));
						image.set_Source(new ImageSourceConverter().ConvertFromString(smileySrc) as ImageSource);
						inlineUIContainer.set_Child(image);
						return inlineUIContainer;
					}
				}
			}
			elementLen = 0;
			elementStr = null;
			return null;
		}
	}
}
